﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Snowdreamist.Collection.Tree
{
    public abstract class TreeBase<T> : ITree<T> where T : ITreeNode<T>
    {
        public virtual ITreeNodeNavigator<T> CreateNavigator()
        {
            return this.Root.CreateNavigator();
        }

        public abstract T CreateTreeNode();

        public T Root { get; protected set; }

        public bool TreeEquals(ITree<T> other)
        {
            if (other == null)
                return false;
            if (object.ReferenceEquals(this, other))
                return true;
            return this.Root.TreeNodeEquals(other.Root);
        }

        public override string ToString()
        {
            StringBuilder strBuilder = new StringBuilder();
            this.Root.ToString(0, strBuilder);
            return strBuilder.ToString();
        }
    }
}